<%@page import="qldc.pm.qtht.dmdc.constants.MaLoaiHoSo"%>
<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@page import="qldc.pm.tienan.constants.ChucNangPhanMemPermision"%>
<%@page import="qldc.pm.qtht.utils.NguoiDungUtils"%>
<%@page import="qldc.pm.qtht.model.ChucNangPhanMem"%>
<%@page import="java.util.List"%>
<%@page import="qldc.pm.tienan.constants.TrangThaiTienAnEnum"%>
<%@page import="qldc.pm.tienan.service.DoiTuongTienAnLocalServiceUtil"%>
<%@page import="qldc.pm.tienan.model.DoiTuongTienAn"%>
<%@page import="qldc.pm.tienan.model.TienAn"%>
<%@page import="com.liferay.portal.kernel.util.Constants"%>
<%@page import="qldc.pm.tienan.model.YeuCauTrichLuc"%>
<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@page import="com.liferay.portal.kernel.dao.search.ResultRow"%>
<%@page import="qldc.pm.tienan.service.TienAnLocalServiceUtil"%>

<%@include file="../../init.jsp"%>


<%
PortletURL redirectToDanhSach = renderResponse.createRenderURL();
redirectToDanhSach.setParameter("mvcPath", "/html/view.jsp");
redirectToDanhSach.setParameter("chonChucNangItem", TienAnConstants.QUAN_LY_NGUOI_CO_TIEN_AN);

ResultRow row = (ResultRow) request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
TienAn tienAn = (TienAn) row.getObject();
long tienAnId = tienAn.getTienAnId();
long doiTuongTienAnId = tienAn.getDoiTuongTienAnId();
DoiTuongTienAn doiTuongTienAn = DoiTuongTienAnLocalServiceUtil.findByDoiTuongTienAnId(doiTuongTienAnId);
String soDinhDanhCaNhan = doiTuongTienAn.getSoDinhDanhCaNhan();

PortletURL redirectURL = renderResponse.createRenderURL();
redirectURL.setParameter("mvcPath", "/html/view.jsp");
redirectURL.setParameter("chonChucNangItem", TienAnConstants.QUAN_LY_NGUOI_CO_TIEN_AN);
redirectURL.setParameter("tabs1", "chi_tiet_tien_an");
redirectURL.setParameter("soDinhDanhCaNhan", soDinhDanhCaNhan);
redirectURL.setParameter("doiTuongTienAnId", String.valueOf(doiTuongTienAn.getDoiTuongTienAnId()));
redirectURL.setParameter("redirect", redirectToDanhSach.toString());



PortletURL inReportURL = renderResponse.createActionURL();
inReportURL.setParameter(TienAnConstants.ACTION_HANDLER_PARAM, TienAnConstants.REPORT_ACTION);
inReportURL.setParameter(Constants.ACTION, "inReportChiTietTienAn");
inReportURL.setParameter("redirect", redirectURL.toString());
inReportURL.setParameter("soDinhDanhCaNhan", soDinhDanhCaNhan);
inReportURL.setParameter("doiTuongTienAnId", String.valueOf(doiTuongTienAn.getDoiTuongTienAnId()));
inReportURL.setParameter("tienAnId", String.valueOf(tienAnId));

TrangThaiTienAnEnum trangThaiTienAn =  TienAnLocalServiceUtil.kiemTraTrangThaiCuaTienAn(tienAn.getTienAnId());
%>

<portlet:renderURL var="currentURL">
	<portlet:param name="mvcPath" value="/html/view.jsp" />
	<portlet:param name="chonChucNangItem" value="<%=TienAnConstants.QUAN_LY_NGUOI_CO_TIEN_AN %>" />
	<portlet:param name="tabs1" value="chi_tiet_tien_an" />
	<portlet:param name="doiTuongTienAnId" value="<%=String.valueOf(doiTuongTienAnId) %>" />
	<portlet:param name="soDinhDanhCaNhan" value="<%=soDinhDanhCaNhan %>" />
	<portlet:param name="redirect" value="<%=redirectToDanhSach.toString()%>" />
</portlet:renderURL>
<liferay-ui:icon-menu  message="thao-tac">
	<portlet:renderURL var="xemTienAnRenderURL">
			<portlet:param name="mvcPath" value="/html/view.jsp"/>
			<portlet:param name="chonChucNangItem" value="<%=TienAnConstants.QUAN_LY_NGUOI_CO_TIEN_AN %>"/>
			<portlet:param name="tabs1" value="xem_tien_an"/>
			<portlet:param name="soDinhDanhCaNhan" value="<%=soDinhDanhCaNhan %>" />
			<portlet:param name="doiTuongTienAnId" value="<%=String.valueOf(doiTuongTienAnId) %>"/>
			<portlet:param name="tienAnId" value="<%=String.valueOf(tienAnId) %>"/>
			<portlet:param name="<%=Constants.CMD %>" value="<%=Constants.VIEW %>" />
			<portlet:param name="redirect" value="<%=currentURL.toString() %>"/>
		</portlet:renderURL>
		
		<liferay-ui:icon image="view" message="xem-thong-tin-tien-an" url="<%=xemTienAnRenderURL.toString() %>" />
	
<%
if(trangThaiTienAn.getValue() == TrangThaiTienAnEnum.DANG_THI_HANH_AN.getValue()) {

%>
		<portlet:renderURL var="suaTienAnRenderURL">
			<portlet:param name="mvcPath" value="/html/view.jsp"/>
			<portlet:param name="chonChucNangItem" value="<%=TienAnConstants.QUAN_LY_NGUOI_CO_TIEN_AN %>"/>
			<portlet:param name="tabs1" value="cap_nhat_tien_an"/>
			<portlet:param name="soDinhDanhCaNhan" value="<%=soDinhDanhCaNhan %>" />
			<portlet:param name="doiTuongTienAnId" value="<%=String.valueOf(doiTuongTienAnId) %>"/>
			<portlet:param name="tienAnId" value="<%=String.valueOf(tienAnId) %>"/>
			<portlet:param name="<%=Constants.CMD %>" value="<%=Constants.EDIT %>" />
			<portlet:param name="redirect" value="<%=currentURL.toString() %>"/>
		</portlet:renderURL>
		
		<liferay-ui:icon image="edit" message="sua-thong-tin-tien-an" url="<%=suaTienAnRenderURL.toString() %>" />
	
		<%
}
		if(trangThaiTienAn.getValue() == TrangThaiTienAnEnum.DANG_THI_HANH_AN.getValue()) {
			List<ChucNangPhanMem> chucNangPhanMems = NguoiDungUtils.getChucNangTheoNguoiDung(MaLoaiHoSo.QLTS.toString(), user.getUserId());
			ChucNangPhanMem xoaAnTich = NguoiDungUtils.getChucNangPhanMem(ChucNangPhanMemPermision.TIENAN_YCXAT.toString(), chucNangPhanMems);
	if (Validator.isNotNull(xoaAnTich)){
		%>
		<portlet:renderURL var="xoaAnTichRenderURL">
			<portlet:param name="mvcPath" value="/html/view.jsp"/>
			<portlet:param name="chonChucNangItem" value="<%=TienAnConstants.QUAN_LY_YEU_CAU_XOA_AN_TICH %>"/>
			<portlet:param name="tabs1" value="xoa_an_tich"/>
			<portlet:param name="tienAnId" value="<%=String.valueOf(tienAnId) %>"/>
			<portlet:param name="soDinhDanhCaNhan" value="<%=soDinhDanhCaNhan %>" />
			<portlet:param name="redirect" value="<%=currentURL.toString() %>"/>
		</portlet:renderURL>
		
		<liferay-ui:icon image="expire" message="lap-ho-so-xoa-an-tich" url="<%=xoaAnTichRenderURL.toString() %>" />
		<%
		}
		}
		%>
		
		<liferay-ui:icon image="print" message="in-thong-tin-tien-an" url="<%=\"javascript:\" + \"inDuLieu(\'\" + inReportURL.toString() + \"\')\" %>" />
		<%
		if(trangThaiTienAn.getValue() == TrangThaiTienAnEnum.DANG_THI_HANH_AN.getValue()) {

		%>
			
		<portlet:actionURL var="xoaTienAnActionURL">
			<portlet:param name="<%=TienAnConstants.ACTION_HANDLER_PARAM %>" value="<%=TienAnConstants.QUAN_LY_NGUOI_CO_TIEN_AN %>"/>
			<portlet:param name="<%=Constants.ACTION %>" value="xoaTienAn"/>
			<portlet:param name="redirect" value="<%=redirectURL.toString() %>"/>
			<portlet:param name="tienAnId" value="<%=String.valueOf(tienAnId) %>"/>
		</portlet:actionURL>
		<liferay-ui:icon-delete message="xoa-tien-an" confirmation="ban-muon-xoa-tien-an-nay" url="<%=xoaTienAnActionURL.toString() %>"></liferay-ui:icon-delete>
	<%} %>
</liferay-ui:icon-menu>

<script>
function inDuLieu(url) {
	var form = $("<form>").attr({action: url, method:"POST",target:"_blank"});				
	form.appendTo(document.body).submit();
	
}
</script>